<template>
  <el-container>
    <el-header>
      <div class="left">
        <img src="@/assets/images/icon.png"/>
        <span>后台管理</span>
      </div>
      <el-button type="danger" @click="exit" >退出</el-button>
    </el-header>
    <el-container class="main-container">
      <el-aside :width="isCollapse? '200px': '38px'" class="aside">
        <div class="toggle-button" @click="toggleCollpase">|||</div>
  <div class="h-6" />
       <el-menu
           class="el-menu-vertical-demo"
           background-color="#333744"
            text-color="#fff"
            :default-active="activeIndex"
            active-text-color="#6cb2fd"
            router
        >
          <el-menu-item index="/admin">
            <el-icon><Grid /></el-icon>
            <span slot="title">数据管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/state">
            <el-icon><MessageBox /></el-icon>
            <span slot="title">状态管理</span>
          </el-menu-item>
          <el-sub-menu index="1-4">
            <template #title>
              <el-icon><Odometer /></el-icon>
              <span>数据监测</span>
          </template>
          <el-menu-item index="/admin/watch">
            <el-icon><Menu /></el-icon>
            <span slot="title">监测管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/user">
            <el-icon><User /></el-icon>
            <span slot="title">短信管理</span>
          </el-menu-item>
        </el-sub-menu>
        <el-menu-item index="/admin/analysis">
           <el-icon><DataLine /></el-icon>
            <span slot="title">数据分析</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
         <el-progress :percentage="store.initNum" color="#4ba0fc" v-if="!isDone"></el-progress>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>
<script setup lang="ts">
  import { ref,computed } from 'vue'
  import {useRouter} from "vue-router";
  import {userStore} from '../../store/user'
  let store = userStore()
  let isCollapse = ref<boolean>(true) // 菜单栏是否展开了
  let router = useRouter()  // 路由对象
  const exit = () => { router.push("/") } // 退出应用程序
  // const activeIndex = ref('/admin/data')
  // 切换菜单按钮
  const toggleCollpase = () => {
     isCollapse.value = !isCollapse.value
  }
 let isDone = computed(() =>store.initNum === 0 || store.initNum === 100)
 let activeIndex = computed(() => {
    return router.currentRoute.value.fullPath
 })
</script>

<style scoped lang="less">
.el-header {
  background-color: #373d3f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    width: 300px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
    img {
      width: 100px;
      height: 100%;
    }
    span {
      color: #fff;
      font-size: 20px;
    }
  }
}
.main-container {
  height: calc(100vh - 60px);
  .toggle-button {
    padding: 0 10px;
    height: 50px;
    text-align: center;
    font-size: 25px;
    color: #fff;
    line-height: 50px;
    background-color: #485166;
  }
  .el-menu {
    height: calc(100% - 50px);
    border-right: none;
    .el-menu-item {
      margin-left: -10px;
    }
    .el-sub-menu {
      margin-left: -10px;
    }
  }
}
.el-main {
  position: relative;
  background: #fff;
  .el-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  }
}
</style>